package org.ali.structuralpattern.compositepattern;

import org.ali.structuralpattern.compositepattern.component.Component1;
import org.ali.structuralpattern.compositepattern.component.Component2;
import org.ali.structuralpattern.compositepattern.node.Branch1;
import org.ali.structuralpattern.compositepattern.node.Branch2;
import org.ali.structuralpattern.compositepattern.node.leaf1;
import org.ali.structuralpattern.compositepattern.node.leaf2;

/**
 * 组合模式
 */
public class Main {
    public static void main(String[] args) {
        Component1 branch1 = new Branch1("1号");

        Component1 leaf1 = new leaf1("1号");
        branch1.add(leaf1);
        Component1 leaf2 = new leaf1("2号");
        branch1.add(leaf2);

        branch1.showMessage();

        Branch2 branch2 = new Branch2("2号");

        Component2 leaf3 = new leaf2("3号");
        branch2.add(leaf3);
        Component2 leaf4 = new leaf2("4号");
        branch2.add(leaf4);

        branch2.showMessage();
    }
}
